<template>
  <a-modal v-model="visible" :width="1080" title="选择预售商品" :footer="null">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="活动id">
              <a-input placeholder="活动id" v-model="queryParam.itemCode"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="活动状态">
              <a-select :default-value="null" v-model="queryParam.activeStatus" placeholder="请选择活动状态" @change="searchQuery">
                <a-select-option :value="null">
                  全部
                </a-select-option>
                <a-select-option :value="1">
                  未开始
                </a-select-option>
                <a-select-option :value="2">
                  进行中
                </a-select-option>
                <a-select-option :value="3">
                  已结束
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>

      <a-table ref="table" size="middle" bordered rowKey="id" :columns="columns" :dataSource="dataSource" :pagination="ipagination" :loading="loading"
        class="j-table-force-nowrap" @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" @click="openUrlView(text)" height="40px" alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="activeStatus" slot-scope="text, record">
          <div v-if="record.activeStatus==1">未开始</div>
          <div v-if="record.activeStatus==2">进行中</div>
          <div v-if="record.activeStatus==3">已结束</div>
        </template>
        <template slot="deposit" slot-scope="text, record">
          {{record.deposit|numToFixed2}}
        </template>
        <template slot="endAmount" slot-scope="text, record">
          {{(Number(record.price)-Number(record.deposit))|numToFixed2}}
        </template>

        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a v-if="selectionType=='radio'" @click="selectItem(record)">选择</a>
        </span>

      </a-table>
    </div>

  </a-modal>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/MyJeecgListMixin'

import JDate from '@/components/jeecg/JDate.vue'

export default {
  name: 'YymsGoodList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    JDate,
  },
  data () {
    return {
      pageCheckedKeys: [],
      noPageCheckedKeys: [],
      pageCheckedRows: [],
      noPageCheckedRows: [],
      visible: false,
      description: '预售商品管理页面',
      // 表头
      columns: [
        {
          title: '活动id',
          dataIndex: 'itemCode',
          align: "left",
          width: 200
        },
        {
          title: '图片',
          align: "center",
          dataIndex: 'imgUrl',
          scopedSlots: { customRender: 'imgSlot' }
        },
        {
          title: '商品名称',
          align: "left",
          dataIndex: 'title'
        },
        {
          title: '商家名称',
          align: "left",
          dataIndex: 'shopName'
        },
        {
          title: '状态',
          align: "center",
          dataIndex: 'isActive',
          scopedSlots: { customRender: 'activeStatus' }
        },
        {
          title: '定金（元）',
          align: "right",
          dataIndex: 'deposit',
          scopedSlots: { customRender: 'deposit' }
        },
        {
          title: '尾款（元）',
          align: "right",
          scopedSlots: { customRender: 'endAmount' }
        }
      ],
      url: {
        list: "/mallPlus/yymsGood/list",
        delete: "/mallPlus/yymsGood/delete",
        deleteBatch: "/mallPlus/yymsGood/deleteBatch",
        exportXlsUrl: "/mallPlus/yymsGood/exportXls",
        importExcelUrl: "mallPlus/yymsGood/importExcel",

      },
      dictOptions: {},
    }
  },
  created () {
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    open (libId) {
      this.queryParam['libId'] = libId
      this.loadData()
    },
    setSelected () {
      this.pageCheckedKeys = []
      this.noPageCheckedKeys = []
      this.pageCheckedRows = []
      this.noPageCheckedRows = []
      for (let i = 0; i < this.checkedKeys.length; i++) {
        let isSelect = false
        for (let j = 0; j < this.dataSource.length; j++) {
          if (this.dataSource[j].id == this.checkedKeys[i]) {
            isSelect = true
          }
        }
        if (isSelect) {
          this.pageCheckedKeys.push(this.checkedKeys[i])
          this.pageCheckedRows.push(this.checkedRows[i])
        } else {
          this.noPageCheckedKeys.push(this.checkedKeys[i])
          this.noPageCheckedRows.push(this.checkedRows[i])
        }
      }
      this.selectedRowKeys = this.pageCheckedKeys
    },
    initDictConfig () {
    }
  }
}
        </script>
<style scoped>
@import '~@assets/less/common.less';
</style>
